package com.lemon.components.ant.util;

import java.io.File;

import com.lemon.components.ant.beans.ProjectInfo;

public class PathUtil {

	private static ProjectInfo projectInfo;
	
	private static PathUtil pathUtil;
	
	private String path;
	
	private PathUtil() {}
	
	public String getServiceBasePackage() {
		return "com."+projectInfo.getCompanyName()+"."+projectInfo.getArtifactId()+".service";
	}
	public String getControllerBasePackage() {
		return "com."+projectInfo.getCompanyName()+"."+projectInfo.getArtifactId()+".controller";
	}
	public String getMyBatisBasePackage() {
		return "com."+projectInfo.getCompanyName()+"."+projectInfo.getArtifactId()+".dal.mybatis";
	}
	
	public static PathUtil getInstance(ProjectInfo projectInfo) {
		PathUtil.projectInfo = projectInfo;
		return pathUtil==null?new PathUtil():pathUtil;
	}

	public PathUtil getModelPath(String model) {
		this.path = projectInfo.getProjectPath()+"/"+projectInfo.getArtifactId()+"/"+projectInfo.getArtifactId()+"-"+model+"/";
		return this;
	}
	
	public String getMybatisModelPath() {
		return this.getJavaSourcePath("dal").getPath()+"/com/"+projectInfo.getCompanyName()+"/"+projectInfo.getArtifactId()+"/dal/mybatis/model/";
	}
	public String getMybatisMapperPath() {
		return this.getJavaSourcePath("dal").getPath()+"/com/"+projectInfo.getCompanyName()+"/"+projectInfo.getArtifactId()+"/dal/mybatis/mapper/";
	}
	public String getMybatisCustomizeMapperPath() {
		return this.getJavaSourcePath("dal").getPath()+"/com/"+projectInfo.getCompanyName()+"/"+projectInfo.getArtifactId()+"/dal/mybatis/mymapper/";
	}
	public String getMybatisCustomizeModelPath() {
		return this.getJavaSourcePath("dal").getPath()+"/com/"+projectInfo.getCompanyName()+"/"+projectInfo.getArtifactId()+"/dal/mybatis/mymodel/";
	}
	public String getMybatisXMLPath() {
		return this.getJavaResourcePath("dal").getPath()+"/mybatis/xml/";
	}
	public String getMybatisCustomizeXMLPath() {
		return this.getJavaResourcePath("dal").getPath()+"/mybatis/myxml/";
	}
	
	public PathUtil getJavaSourcePath(String model) {
		this.path = getModelPath(model).getPath()+"src/main/java/";
		return this;
	}
	
	public PathUtil getJavaTestSourcePath(String model) {
		this.path = getModelPath(model).getPath()+"src/test/java/";
		return this;
	}
	
	public PathUtil getJavaResourcePath(String model) {
		this.path = getModelPath(model).getPath()+"src/main/resources/";
		return this;
	}
	
	public PathUtil getTestJavaSourcePath(String model) {
		this.path = getModelPath(model).getPath()+"src/test/java/";
		return this;
	}
	
	public PathUtil getTestJavaResourcePath(String model) {
		this.path = getModelPath(model).getPath()+"/src/test/resources/";
		return this;
	}
	
	public PathUtil getServicePackagePath() {
		this.path = getJavaSourcePath("biz").getPath()+"com/"+projectInfo.getCompanyName()+"/"+projectInfo.getArtifactId()+"/service/";
		return this;
	}
	
	public PathUtil getControllerPackagePath() {
		this.path = getJavaSourcePath("web").getPath()+"com/"+projectInfo.getCompanyName()+"/"+projectInfo.getArtifactId()+"/controller/";
		return this;
	}
	
	public PathUtil getDalPackagePath() {
		this.path = getJavaSourcePath("dal").getPath()+"com/"+projectInfo.getCompanyName()+"/"+projectInfo.getArtifactId()+"/dal/";
		return this;
	}
	
	public PathUtil getAssemblePackagePath() {
		this.path = getJavaSourcePath("assemble").getPath()+"com/"+projectInfo.getCompanyName()+"/"+projectInfo.getArtifactId()+"/";
		return this;
	}
	
	public PathUtil getTestPackagePath() {
		this.path = getJavaTestSourcePath("test").getPath()+"com/"+projectInfo.getCompanyName()+"/"+projectInfo.getArtifactId()+"/";
		return this;
	}
	
	public PathUtil getConfigPackagePath() {
		this.path = getJavaSourcePath("config").getPath()+"com/"+projectInfo.getCompanyName()+"/"+projectInfo.getArtifactId()+"/config/";
		return this;
	}
	
	public File getFile() {
		return new File(this.path);
	}
	
	public void makedir() {
		File file = new File(this.path);
		file.mkdirs();
	}

	public String getPath() {
		return path;
	}
	
}
